<?php
//DB Created by Rich L. a member in service in Northern Delaware.  Please feel free to share this code wherever it may be useful to alcholoics.  Should you have questons please contact me at sobernerd@gmail.com
if ($_SESSION['logged_in'] == 0) {
require ('../../admin/security_check.php');
} else {

if ($_POST)
{
	processTable('meetings');
}		
/* meetings query */
			$sql = "SELECT meetings.id AS id, day, mtime, city, name, room, group_id, groupname, code, open_closed, men_women, hc 
							FROM meetings,groups,locations,meeting_types 
							WHERE group_id=groups.id and location_id=locations.id and mtg_type_id=meeting_types.id ORDER BY day, mtime, city ASC";
			$result = mysql_query($sql) or die(mysql_error());
					
			$num_rows = mysql_num_rows($result); ?>

      <table class="tabletext">
      <thead class="meetingHeader">
      <tr class="titleRow">
		<th colspan="9"><h3>Meetings&nbsp;&nbsp;&nbsp;(<?php echo $num_rows ?>)</h3></th>
    </tr>
        <tr class="alternateRow">
          <th>Day/Time</th>
          <th>City</th>
          <th>Group</th>
          <th>Location</th>
          <th>O/C</th>
          <th>Type</th>
          <th>M/W</th>
          <th>HC</th>
          <th></th>
        </tr>
      </thead>
        <?php		


$i = 0;
$dayheader = 0;
// Get each row of data on each iteration until
// there is no more rows
// this code can be used or "while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))" can be used

//outer loop begin
while ($row = mysql_fetch_assoc($result))
{
		$dayName = getDay($row['day']);
		// Set Time variables for reading
		$meeting_time=$row['mtime'];
		$rawtime = strtotime($meeting_time);	
		$meeting_time = date('g:iA',$rawtime);
		$city=$row['city'];
		$groupname=$row['groupname'];
		$room=$row['room'];
		$group_id=$row['group_id'];			
		$location_name=$row['name'];
		$meeting_types_code=$row['code'];
			
		// set row color		
		if ($i%2 == 0) 
		{
		$rowcolor="$reprowcolor";
		} else 
		{
		$rowcolor="white";
		}
		// set heading in new day
		if ($dayheader != $row['day'])
		{echo "<tr><td class=\"dayheader\" colspan=\"9\"><div align=\"left\">$dayName</div></td></tr>";
		$dayheader = $row['day'];}
		
		?>
        <tr bgcolor="<?php echo $rowcolor?>">
          <td><div class="meetingTime"><?php echo "$meeting_time";?></div></a></td>
          <td><div class="meetingCity"><?php echo "$city";?></div></td>
          <td><div class="meetingGroupName"><?php echo "$groupname";?></div></td>
          <td><div class="meetingLocation"><?php echo "$location_name";?><?php if ($room)echo " - $room" ?></div></td>
          <td><div class="meetingOpenClosed"><?php echo "$row[open_closed]";?></div></td>
          <td><div class="meetingType"><?php echo "$meeting_types_code";?></div></td>
          <td><div class="meetingMenWomen"><?php echo "$row[men_women]";?></div></td>
          <td><div class="meetingHC"><?php echo "$row[hc]";?></div></td>
          <td><div class="meetingDelete">
          		<a href="meetings.php?page=meeting_edit&id=<?php echo $row['id']?>&return_to=meetings.php"><img src="../images/edit_button.png"></a>
          		<a title="Delete" href="deleteform.php?id=<?php echo $row['id']?>&table=meetings&return_to=meetings.php"><img src="../images/delete_button.png"></a>
              </div>
          </td>
        </tr>
        <?php 
										
	$i++;	
// Outer loop end (group)						
}
echo "</table>";
mysql_close($conn);}?>
      </table>